package model

import (
	"gorm.io/gorm"
	"hotel_3.27/variable"
)

type Hotel struct {
	gorm.Model
	Name      string  `gorm:"type:varchar(20);not null;index:ip_idx"`
	Price     float64 `gorm:"type:decimal(10,2);not null;index:ip_idx"`
	Stock     int64   `gorm:"type:int;not null;index:ip_idx"`
	Address   string  `gorm:"type:varchar(50);not null;index:ip_idx"`
	HotelType int64   `gorm:"type:int;not null;index:ip_idx"`
}

func (h Hotel) FindHotelId(id int64) (hotel *Hotel, err error) {
	err = variable.DB.Where("id=?", id).Take(&hotel).Error
	if err != nil {
		return nil, err
	}
	return
}

type HotelAttribute struct {
	gorm.Model
	HotelId int64   `gorm:"type:int;not null;index:ip_idx"`
	Name    string  `gorm:"type:varchar(20);not null;index:ip_idx"`
	Price   float64 `gorm:"type:decimal(10,2);not null;index:ip_idx"`
}
